#coding:utf-8
#author:wolf
import os
def run(ip_list,path,rate):
    try:
        ip_file = open('target.log','w')
        ip_file.write("\n".join(ip_list))
        ip_file.close()
        path = str(path).translate(None, ';|&`\n')
        rate = str(rate).translate(None, ';|&`\n')
        if not os.path.exists(path):return
        # os.system("%s -p1-65535 -iL target.log -oL tmp.log --randomize-hosts --rate=%s"%(path,rate))
        # 修改为只扫描常用端口
        os.system("%s -p21,22,23,25,53,69,80-91,110,139,143,389,443,445,465,666,678,777,873,888,993,995,999,1080,1111,1158,1234,1311,1433,1521,1723,2100,2222,3000-3011,3050,3128,3306,3333,3389,3443,3690,4000,4071,4444,5000,5011,5015,5019,5432,5533,5555,5566,5601,5801,5900,6060,6080,6379,6588,6666,6677,6688,6868,6869,7001,7301,7777,7788,7789,8000-8013,8040,8042,8080-8090,8097,8223,8235,8237,8300,8888,8899,8900,8909,8983,8999,9000,9080,9090,9112,9200,9300,9999,10086,11211,15672,16030,18080,18088,20001,20015,20019,20032,20040,22004,27017,28080,30001,30030,33001,33060,33066,33306,33890,33899,34001,40081,50181,50281,50381,51081,55555,57943,57980,57981,57992,57993 -iL target.log -oL tmp.log --randomize-hosts --rate=%s"%(path,rate))
        result_file = open('tmp.log', 'r')
        result_json = result_file.readlines()
        result_file.close()
        del result_json[0]
        del result_json[-1]
        open_list = {}
        for res in result_json:
            try:
                ip = res.split()[3]
                port = res.split()[2]
                if ip in open_list:
                    open_list[ip].append(port)
                else:
                    open_list[ip] = [port]
            except:pass
        os.remove('target.log')
        os.remove('tmp.log')
        return open_list
    except:
        pass
